<?php
function connect(){
	$host = '127.0.0.1';
	$user = 'root';
	$pass = '';
	
	$link = mysql_connect($host, $user, $pass);
	mysql_select_db('stu_question');
	mysql_query("set names 'utf8'");
	
	return $link;
}

function fetchTags(){
	$result= mysql_query('SELECT DISTINCT tag FROM question');
	
	$data = array();
	while ($row = mysql_fetch_array($result)) {
		$data[] = $row;
	}
	
	return $data;
}

function fetchQuestion($type, $tag, $limit,$difficulty){
	$sql = 'SELECT content,tag,level,img from question where type="'.$type.'" and difficulty="'.$difficulty.'" and tag="'.$tag.'" order by rand() limit '.$limit;
	$result= mysql_query($sql);
	
	$data = array();
	while ($row = mysql_fetch_array($result)) {
		$data[] = $row;
	}
	
	return $data;
}
